﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataAccess;
using Business;
using Foundation.View;
using Foundation;

namespace RPGSoundmixer.SoundSuiteExplorer {
    public partial class SoundSuiteExplorerView : Form {
        private SoundSuiteExplorerPresenter presenter;
        private IDataHandler model;         
        
        public SoundSuiteExplorerView() {
            InitializeComponent();
            this.presenter = new SoundSuiteExplorerPresenter(this); 
            this.model = DataHandler.GetInstance(); 
            this.model.PropertyChanged+=new PropertyChangedEventHandler(model_PropertyChanged);

            this.cmbSuites.Items.AddRange(this.model.SoundSuites.ToArray()); 
        }

        void model_PropertyChanged(object sender, PropertyChangedEventArgs e) {
            if (e.PropertyName.Equals("SoundSuite")) {
                this.cmbSuites.SelectedItem = null; 
                this.cmbSuites.Items.Clear();
                this.cmbSuites.Items.AddRange(this.model.SoundSuites.ToArray()); 
            }
        }

        private void button3_Click(object sender, EventArgs e) {
            using (InputBox ibox = new InputBox()) {
                ibox.Title = "Neue Soundsuite";
                var result = ibox.ShowDialog(); 
                if (result != DialogResult.Cancel) {
                    this.presenter.createSuite(ibox.TextBoxValue);
                }
            }
        }

        private void button4_Click(object sender, EventArgs e) {
            if (this.cmbSuites.SelectedItem != null) {
                this.presenter.deleteSuite((SoundSuite)this.cmbSuites.SelectedItem); 
            }
        }

        private void btOK_Click(object sender, EventArgs e) {
            if (this.cmbSuites.SelectedItem != null) {
                this.presenter.SetCurrentSuite(this.cmbSuites.SelectedItem as SoundSuite);
                this.Close(); 
            }
            else {
                MessageBox.Show("Es wurde keine Sound Suite ausgewählt. Bitte wählen sie eine aus oder brechen sie den Vorgang ab", 
                    "Keine Sound Suite ausgewählt", MessageBoxButtons.OK, MessageBoxIcon.Information );
            }
        }

        private void btCancel_Click(object sender, EventArgs e) {
            this.Close(); 
        }
    }
}
